package com.qyhl.module_practice.activity;


import com.qyhl.module_practice.common.PracticeUrl;
import com.qyhl.webtv.basiclib.utils.network.EasyHttp;
import com.qyhl.webtv.basiclib.utils.network.callback.SimpleCallBack;
import com.qyhl.webtv.basiclib.utils.network.exception.ApiException;
import com.qyhl.webtv.commonlib.common.CommonUtils;
import com.qyhl.webtv.commonlib.entity.civilized.PracticeAcitivityBean;

import java.util.List;

public class PracticeActModel implements PracticeActContract.PracticeActModel {
    private PracticeActPresenter mPresenter;

    PracticeActModel(PracticeActPresenter mPresenter) {
        this.mPresenter = mPresenter;
    }

    @Override
    public void getStreetList(String streetId, final String page, String userName) {
        EasyHttp.get(PracticeUrl.GET_PRACTICE_STREET_ACT_LIST)
                .params("instId", streetId)
                .params("page", page)
                .params("phone", userName)
                .execute(new SimpleCallBack<List<PracticeAcitivityBean>>() {
                    @Override
                    public void onError(ApiException e) {
                        if (e.getCode() == 202) {
                            mPresenter.setError("暂无任何内容！", !page.equals("1"));
                        } else {
                            mPresenter.setError("请求出错，请重新获取！", !page.equals("1"));
                        }
                    }

                    @Override
                    public void onSuccess(List<PracticeAcitivityBean> practiceAcitivityBeans) {
                        if (practiceAcitivityBeans != null && practiceAcitivityBeans.size() > 0) {
                            mPresenter.setList(practiceAcitivityBeans, !page.equals("1"));
                        } else {
                            mPresenter.setError("暂无任何内容！", !page.equals("1"));
                        }
                    }
                });
    }

    @Override
    public void getList(final String page, String status, String keyword, String type) {
        EasyHttp.get(PracticeUrl.GET_PRACTICE_ACT_SELECT)
                .params("siteId", CommonUtils.getInstance().getSite() + "")
                .params("status", status)
                .params("page", page)
                .params("type", type)
                .params("key", keyword)
                .execute(new SimpleCallBack<List<PracticeAcitivityBean>>() {
                    @Override
                    public void onError(ApiException e) {
                        if (e.getCode() == 202) {
                            mPresenter.setError("暂无任何内容！", !page.equals("1"));
                        } else {
                            mPresenter.setError("请求出错，请重新获取！", !page.equals("1"));
                        }
                    }

                    @Override
                    public void onSuccess(List<PracticeAcitivityBean> practiceAcitivityBeans) {
                        if (practiceAcitivityBeans != null && practiceAcitivityBeans.size() > 0) {
                            mPresenter.setList(practiceAcitivityBeans, !page.equals("1"));
                        } else {
                            mPresenter.setError("暂无任何内容！", !page.equals("1"));
                        }
                    }
                });

    }

    @Override
    public void getOrgList(String orgId, final String page) {
        
        
        EasyHttp.get(PracticeUrl.GET_PRACTICE_TEAM_ACT_LIST)
                .params("orgId", orgId)
                .params("page", page)
                .execute(new SimpleCallBack<List<PracticeAcitivityBean>>() {
                    @Override
                    public void onError(ApiException e) {
                        if (e.getCode() == 202) {
                            mPresenter.setError("暂无任何内容！", !page.equals("1"));
                        } else {
                            mPresenter.setError("请求出错，请重新获取！", !page.equals("1"));
                        }
                    }

                    @Override
                    public void onSuccess(List<PracticeAcitivityBean> practiceAcitivityBeans) {
                        if (practiceAcitivityBeans!= null && practiceAcitivityBeans.size() > 0) {
                            mPresenter.setList(practiceAcitivityBeans, !page.equals("1"));
                        } else {
                            mPresenter.setError("暂无任何内容！", !page.equals("1"));
                        }
                    }
                });
    }


}
